package cn.jimmie.lib.qlog.support;

import android.database.Cursor;

import java.io.Closeable;
import java.net.HttpURLConnection;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;

/**
 * function :
 *
 * <p> Create Time:  2019年03月07日 17:14 </p>
 * <p> @author Jimmie.Qian  </p>
 */
public final class AlIO {
    public static void close(Closeable closeable) {
        if (closeable == null) return;
        try {
            closeable.close();
        } catch (Throwable ignored) {
        }
    }

    public static void close(Process p) {
        if (p == null) return;
        try {
            p.destroy();
        } catch (Throwable ignored) {

        }
    }

    public static void close(Socket socket) {
        if (socket == null) return;
        try {
            socket.close();
        } catch (Exception ignored) {

        }
    }

    public static void close(ServerSocket socket) {
        if (socket == null) return;
        try {
            socket.close();
        } catch (Exception ignored) {

        }
    }

    public static void close(HttpURLConnection connection) {
        if (connection == null) return;
        try {
            connection.disconnect();
        } catch (Exception ignored) {

        }
    }

    public static void close(ExecutorService service) {
        if (service == null) return;
        try {
            service.shutdownNow();
        } catch (Exception ignored) {

        }
    }

    public static void close(Cursor cursor) {
        if (cursor == null) return;
        try {
            cursor.close();
        } catch (Exception ignored) {
        }
    }
}
